(function (vc, vm) {
    vc.extends({
        data: {
            editShopHouseInfo: {
                shId: '',
                shName: '',
                shTypes: [],
                shType: '',
                shDesc: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editShopHouse', 'openEditShopHouseModal', function (_params) {
                $that.refreshEditShopHouseInfo();
                vc.getDict('s_shop_house', "sh_type", function (_data) {
                    $that.editShopHouseInfo.shTypes = _data;
                });
                $('#editShopHouseModel').modal('show');
                vc.copyObject(_params, $that.editShopHouseInfo);
                $that.editShopHouseInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editShopHouseValidate: function () {
                return vc.validate.validate({
                    editShopHouseInfo: $that.editShopHouseInfo
                }, {
                    'editShopHouseInfo.shName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "仓库名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "仓库名称太长"
                        },
                    ],
                    'editShopHouseInfo.shType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "仓库类型不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "仓库类型格式错误"
                        },
                    ],
                    'editShopHouseInfo.shDesc': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "描述不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "描述太长"
                        },
                    ],
                    'editShopHouseInfo.shId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "仓库编号不能为空"
                        }
                    ]
                });
            },
            editShopHouse: function () {
                if (!$that.editShopHouseValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    '/shopHouse/updateShopHouse',
                    JSON.stringify($that.editShopHouseInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editShopHouseModel').modal('hide');
                            vc.emit('shopHouseManage', 'listShopHouse', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditShopHouseInfo: function () {
                let _shTypes = $that.editShopHouseInfo.shTypes;
                $that.editShopHouseInfo = {
                    shId: '',
                    shName: '',
                    shTypes: _shTypes,
                    shType: '',
                    shDesc: ''
                }
            }
        }
    });
})(window.vc, window.vc.component);
